import { post, post2 } from 'utils/fetch';

// 获取流程列表数据
export const getListData = (params) => {
  return post('/flow-platform/model/list', params);
}

// 创建流程
export const addFlow = ({
  description, key, name, appId, busiId, properties,
}) => {
  return post('/flow-platform/model/create', { description, key, name, appId, busiId, properties });
}

// 导入流程
export const importFlow = (
  data,
) => {
  return post2('/flow-platform/model/upload/json',  data );
}

// 创建流程(去掉cbd自带弹窗)
export const addFlowNoCheck = ({
  description, key, name, appId, busiId, properties,
}) => {
  return post('/flow-platform/model/create', { description, key, name, appId, busiId, properties }, { isCheck: false });
}

// 复制流程
export const copyFlow = ({
  originModelId, description, key, name, appId, busiId, properties,
}) => {
  return post('/flow-platform/model/copy', { originModelId, description, key, name, appId, busiId, properties }, { messageType: 'close' });
}

// 删除流程
export const delFlow = ({ modelId }) => {
  return post('/flow-platform/model/delete', { modelId });
}

// 流程详情
export const modelDetail = ({ modelId }) => {
  return post(`/flow-platform/model/detail`, { modelId });
}

// 流程部署
export const processDeploy = ({ modelId }) => {
  return post(`/flow-platform/model/deploy`, { modelId }, { isCheck: false });
}

// 获取流程关联变量
export const getModelVariables = data =>
  post('/flow-platform/model/getModelVariables', data)

// 流程下线
export const processOffline = ({ modelId }) => {
  return post(`/flow-platform/model/offline`, { modelId }, { isCheck: false });
}

// 版本管理
export const modelDetailList = (params) => {
  return post(`/flow-platform/model/modelDetailList`, params);
}

export const checkModelExist = (params) => {
  const {modelName='', modelKey=''} = params;
  return post(`/flow-platform/model/checkModelExist?modelName=${modelName}&modelKey=${modelKey}`);
}
